package com.distributer.delayqueue.delayqueue.event;

import com.distributer.delayqueue.job.JobMsg;
import com.distributer.delayqueue.job.JobStatus;


public class RedisJobEventListener implements JobEventListener {

    private RdbStore store;

    public void setStore(RdbStore store) {
        this.store = store;
    }

	@Override
	public void listener(JobEvent event) {
	 if (event instanceof RedisJobTraceEvent) {
            RedisJobTraceEvent e   = (RedisJobTraceEvent) event;
            JobMsg  job = e.getJob();
            if (e.getRdbOperation() == RdbOperation.INSERT && job.getStatus() != JobStatus.Restore.ordinal()) {
                store.insertJob(job);
            } else {
                store.updateJobsStatus(job);
            }
        }
	}
}
